// 防抖
const antiShakingFun = () => {
  let timer = null;
  return (callBack, times, ...res) => {
    if (!times) {
      times = 500;
    }
    if (timer) {
      clearTimeout(timer);
      timer = null;
    }
    timer = setTimeout(() => {
      if (res) {
        // eslint-disable-next-line prefer-spread
        callBack.apply(null, res);
      } else {
        callBack();
      }

      clearTimeout(timer);
      timer = null;
    }, times);
  };
};

const antiShaking = antiShakingFun();
export default antiShaking;
